package ch.janotta.slawo.da.tables;

import java.util.HashMap;

import ch.janotta.slawo.da.Background;
import ch.janotta.slawo.da.People;

public final class BackgroundModifiersTableFactory {
  private enum TableKey {
    ELVEN_APOSTATE,
    HUMAN_APOSTATE,
    AVVAR,
    ELVEN_CIRCLE_MAGE,
    HUMAN_CIRCLE_MAGE,
    CITY_ELF,
    DALISH_ELF,
    FERELDAN_FREEMAN,
    SURFACE_DWARF,
    ;

    public static TableKey parse(Background background, People people) {
      switch (background) {
        case Apostate:
          if (people == People.ELF) return ELVEN_APOSTATE;
          if (people == People.HUMAN) return HUMAN_APOSTATE;
          break;
        case Avvar:
          if (people == People.HUMAN) return AVVAR;
          break;
        case Circle_Mage:
          if (people == People.ELF) return ELVEN_CIRCLE_MAGE;
          if (people == People.HUMAN) return HUMAN_CIRCLE_MAGE;
          break;
        case City_Elf:
          if (people == People.ELF) return CITY_ELF;
          break;
        case Dalish_Elf:
          if (people == People.ELF) return DALISH_ELF;
          break;
        case Fereldan_Freeman:
          if (people == People.HUMAN) return FERELDAN_FREEMAN;
          break;
        case Surface_Dwarf:
          if (people == People.DWARF) return SURFACE_DWARF;
          break;
      }
      return null;
    }
  }

  private static HashMap<TableKey, BackgroundStartingModifiersTable> MODIFIERS_TABLE = new HashMap<>();
  static {
    MODIFIERS_TABLE.put(TableKey.ELVEN_APOSTATE,    new ElvenApostateStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.HUMAN_APOSTATE,    new HumanApostateStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.AVVAR,             new AvvarStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.ELVEN_CIRCLE_MAGE, new ElvenCircleMageStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.HUMAN_CIRCLE_MAGE, new HumanCircleMageStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.CITY_ELF,          new CityElfStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.DALISH_ELF,        new DalishElfStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.FERELDAN_FREEMAN,  new FereldanFreemanStartingModifiersTable());
    MODIFIERS_TABLE.put(TableKey.SURFACE_DWARF,     new SurfaceDwarfStartingModifiersTable());
  }

  // Disable the constructor. No instantiation of class possible.
  private BackgroundModifiersTableFactory() {}

  public static BackgroundStartingModifiersTable getBackgroundModifiersTable(Background background, People people) {
    TableKey key = TableKey.parse(background, people);
    return MODIFIERS_TABLE.get(key);
  }
}
